package com.qijian.maindata.domain.query;


import com.baomidou.mybatisplus.annotation.TableName;
import com.qijian.common.utils.mybatis.WhereType;
import com.qijian.common.utils.mybatis.WhereTypeEnum;
import lombok.Data;
import lombok.ToString;

import javax.validation.constraints.NotBlank;
import java.util.Set;


/**
 * 通用树形分类对象 查询条件类
 *
 * @author qijian
 * @date 2021-12-23
 */

@Data
@ToString
@TableName("sys_classify")
public class CommonClassifyQuery {

    @WhereType(filed = "id")
    private Long id;
    @WhereType(filed = "classify_type")
    @NotBlank(message = "分类不允许为空")
    private String classifyType;
    @WhereType(filed = "code", sort = true, sortType = WhereTypeEnum.ASC)
    private String code;
    @WhereType(filed = "name")
    private String name;
    @WhereType(filed = "top_classify_id")
    private Long topClassifyId;
    @WhereType(filed = "parent_classify_id")
    private Long parentClassifyId;
    @WhereType(filed = "id", type = WhereTypeEnum.IN)
    private Set<Long> ids;

    @WhereType(func = "EXISTS ( " +
            "SELECT distinct c.top_classify_id FROM main_bom b  " +
            "INNER JOIN main_item i ON b.item_id = i.item_id " +
            "INNER JOIN sys_classify c ON i.item_classify_id = c.id " +
            "WHERE  b.is_del = 0 " +
            "and i.is_del = 0 " +
            "and i.item_classify >0 " +
            "AND sys_classify.top_classify_id = c.top_classify_id AND FIND_IN_SET(sys_classify.id,c.ancestors)" +
            ")")
    private Boolean isBomClass;

    @WhereType(filed = "ancestors",type = WhereTypeEnum.LIKE_RIGHT)
    private String ancestorsLikeRight;

    @WhereType(filed = "ancestors",func = " (LENGTH( sys_classify.ancestors ) - LENGTH(REPLACE ( sys_classify.ancestors, ',', '' ))) / LENGTH( ',' )  <{1}")
    private Long level;

    @WhereType(ignore = true)
    private String factoryArea;
}
